// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//


#include <pollux/functions/sparksql/registration/register.h>

#include <gtest/gtest.h>

#include <pollux/expression/cast_expr.h>
#include <pollux/expression/special_form_registry.h>
#include <pollux/functions/registerer.h>
#include <tests/functions/registry_test_util.h>

namespace kumo::pollux::functions::sparksql::test {

POLLUX_DECLARE_VECTOR_FUNCTION(
    udf_vector_func_one,
    VectorFuncOne::signatures(),
    std::make_unique<VectorFuncOne>());

class RegisterTest : public testing::Test {
 public:
  RegisterTest() {
    register_function<FuncTwo, int64_t, double, double>(
        {"func_two_double", "Func_Two_Double_Alias"});
    register_function<FuncTwo, int64_t, int64_t, int64_t>({"func_two_bigint"});

    POLLUX_REGISTER_VECTOR_FUNCTION(udf_vector_func_one, "vector_func_one");
    POLLUX_REGISTER_VECTOR_FUNCTION(
        udf_vector_func_one, "Vector_Func_One_Alias");

    exec::registerFunctionCallToSpecialForm(
        "cast", std::make_unique<exec::CastCallToSpecialForm>());
  }
};

TEST_F(RegisterTest, listFunctionNames) {
  auto names = listFunctionNames();
  EXPECT_EQ(names.size(), 6);
  std::sort(names.begin(), names.end());

  EXPECT_EQ(names[0], "cast");
  EXPECT_EQ(names[1], "func_two_bigint");
  EXPECT_EQ(names[2], "func_two_double");
  EXPECT_EQ(names[3], "func_two_double_alias");
  EXPECT_EQ(names[4], "vector_func_one");
  EXPECT_EQ(names[5], "vector_func_one_alias");
}

} // namespace kumo::pollux::functions::sparksql::test
